package gt.edu.usac.viewcontroller.backing.app;

import gt.edu.usac.model.am.AppModuleImpl;

import gt.edu.usac.model.vo.idiomaNivelSeccionViewImpl;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlForm;

import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.event.ValueChangeEvent;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCDataControl;
import oracle.adf.view.faces.component.core.data.CoreColumn;
import oracle.adf.view.faces.component.core.data.CoreTable;
import oracle.adf.view.faces.component.core.input.CoreSelectOneChoice;
import oracle.adf.view.faces.component.core.layout.CorePanelForm;
import oracle.adf.view.faces.component.core.layout.CorePanelHeader;
import oracle.adf.view.faces.component.core.layout.CorePanelTip;
import oracle.adf.view.faces.component.core.nav.CoreCommandLink;
import oracle.adf.view.faces.component.core.output.CoreOutputText;

import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;

import oracle.jbo.ApplicationModule;
import oracle.jbo.Row;

public class Actas {
    private HtmlForm form1;
    private BindingContainer bindings;
    private CorePanelHeader panelHeader1;
    private CorePanelTip panelTip1;
    private CoreOutputText outputText1;
    private CorePanelForm panelForm1;
    private CoreSelectOneChoice selectOneChoice1;
    private UISelectItems selectItems1;
    private CoreSelectOneChoice selectOneChoice2;
    private UISelectItems selectItems2;
    private CoreSelectOneChoice selectOneChoice3;
    private UISelectItems selectItems3;
    private CoreSelectOneChoice selectOneChoice4;
    private UISelectItems selectItems4;
    private CorePanelTip panelTip2;
    private CoreOutputText outputText2;
    private CoreTable table1;
    private CoreColumn column1;
    private CoreColumn column2;
    private CoreOutputText outputText4;
    private CoreColumn column3;
    private CoreOutputText outputText5;
    private CoreColumn column4;
    private CoreOutputText outputText6;
    private CoreColumn column5;
    private CoreOutputText outputText7;
    private CoreColumn column6;
    private CoreOutputText outputText8;
    private CoreColumn column7;
    private CoreOutputText outputText9;
    private CoreColumn column8;
    private CoreOutputText outputText10;
    private CoreColumn column9;
    private CoreOutputText outputText11;
    private CoreColumn column10;
    private CoreOutputText outputText12;
    private CoreCommandLink outputText3;

    public void setForm1(HtmlForm form1) {
        this.form1 = form1;
    }

    public HtmlForm getForm1() {
        return form1;
    }

    public void setPanelHeader1(CorePanelHeader panelHeader1) {
        this.panelHeader1 = panelHeader1;
    }

    public CorePanelHeader getPanelHeader1() {
        return panelHeader1;
    }

    public void setPanelTip1(CorePanelTip panelTip1) {
        this.panelTip1 = panelTip1;
    }

    public CorePanelTip getPanelTip1() {
        return panelTip1;
    }

    public void setOutputText1(CoreOutputText outputText1) {
        this.outputText1 = outputText1;
    }

    public CoreOutputText getOutputText1() {
        return outputText1;
    }


    public void setPanelForm1(CorePanelForm panelForm1) {
        this.panelForm1 = panelForm1;
    }

    public CorePanelForm getPanelForm1() {
        return panelForm1;
    }

    public void setSelectOneChoice1(CoreSelectOneChoice selectOneChoice1) {
        this.selectOneChoice1 = selectOneChoice1;
    }

    public CoreSelectOneChoice getSelectOneChoice1() {
        return selectOneChoice1;
    }

    public void setSelectItems1(UISelectItems selectItems1) {
        this.selectItems1 = selectItems1;
    }

    public UISelectItems getSelectItems1() {
        return selectItems1;
    }

    public void setSelectOneChoice2(CoreSelectOneChoice selectOneChoice2) {
        this.selectOneChoice2 = selectOneChoice2;
    }

    public CoreSelectOneChoice getSelectOneChoice2() {
        return selectOneChoice2;
    }

    public void setSelectItems2(UISelectItems selectItems2) {
        this.selectItems2 = selectItems2;
    }

    public UISelectItems getSelectItems2() {
        return selectItems2;
    }

    public void setSelectOneChoice3(CoreSelectOneChoice selectOneChoice3) {
        this.selectOneChoice3 = selectOneChoice3;
    }

    public CoreSelectOneChoice getSelectOneChoice3() {
        return selectOneChoice3;
    }

    public void setSelectItems3(UISelectItems selectItems3) {
        this.selectItems3 = selectItems3;
    }

    public UISelectItems getSelectItems3() {
        return selectItems3;
    }

    public void setSelectOneChoice4(CoreSelectOneChoice selectOneChoice4) {
        this.selectOneChoice4 = selectOneChoice4;
    }

    public CoreSelectOneChoice getSelectOneChoice4() {
        return selectOneChoice4;
    }

    public void setSelectItems4(UISelectItems selectItems4) {
        this.selectItems4 = selectItems4;
    }

    public UISelectItems getSelectItems4() {
        return selectItems4;
    }

    public void setPanelTip2(CorePanelTip panelTip2) {
        this.panelTip2 = panelTip2;
    }

    public CorePanelTip getPanelTip2() {
        return panelTip2;
    }

    public void setOutputText2(CoreOutputText outputText2) {
        this.outputText2 = outputText2;
    }

    public CoreOutputText getOutputText2() {
        return outputText2;
    }

    public void setTable1(CoreTable table1) {
        this.table1 = table1;
    }

    public CoreTable getTable1() {
        return table1;
    }

    public void setColumn1(CoreColumn column1) {
        this.column1 = column1;
    }

    public CoreColumn getColumn1() {
        return column1;
    }


    public void setColumn2(CoreColumn column2) {
        this.column2 = column2;
    }

    public CoreColumn getColumn2() {
        return column2;
    }

    public void setOutputText4(CoreOutputText outputText4) {
        this.outputText4 = outputText4;
    }

    public CoreOutputText getOutputText4() {
        return outputText4;
    }

    public void setColumn3(CoreColumn column3) {
        this.column3 = column3;
    }

    public CoreColumn getColumn3() {
        return column3;
    }

    public void setOutputText5(CoreOutputText outputText5) {
        this.outputText5 = outputText5;
    }

    public CoreOutputText getOutputText5() {
        return outputText5;
    }

    public void setColumn4(CoreColumn column4) {
        this.column4 = column4;
    }

    public CoreColumn getColumn4() {
        return column4;
    }

    public void setOutputText6(CoreOutputText outputText6) {
        this.outputText6 = outputText6;
    }

    public CoreOutputText getOutputText6() {
        return outputText6;
    }

    public void setColumn5(CoreColumn column5) {
        this.column5 = column5;
    }

    public CoreColumn getColumn5() {
        return column5;
    }

    public void setOutputText7(CoreOutputText outputText7) {
        this.outputText7 = outputText7;
    }

    public CoreOutputText getOutputText7() {
        return outputText7;
    }

    public void setColumn6(CoreColumn column6) {
        this.column6 = column6;
    }

    public CoreColumn getColumn6() {
        return column6;
    }

    public void setOutputText8(CoreOutputText outputText8) {
        this.outputText8 = outputText8;
    }

    public CoreOutputText getOutputText8() {
        return outputText8;
    }

    public void setColumn7(CoreColumn column7) {
        this.column7 = column7;
    }

    public CoreColumn getColumn7() {
        return column7;
    }

    public void setOutputText9(CoreOutputText outputText9) {
        this.outputText9 = outputText9;
    }

    public CoreOutputText getOutputText9() {
        return outputText9;
    }

    public void setColumn8(CoreColumn column8) {
        this.column8 = column8;
    }

    public CoreColumn getColumn8() {
        return column8;
    }

    public void setOutputText10(CoreOutputText outputText10) {
        this.outputText10 = outputText10;
    }

    public CoreOutputText getOutputText10() {
        return outputText10;
    }

    public void setColumn9(CoreColumn column9) {
        this.column9 = column9;
    }

    public CoreColumn getColumn9() {
        return column9;
    }

    public void setOutputText11(CoreOutputText outputText11) {
        this.outputText11 = outputText11;
    }

    public CoreOutputText getOutputText11() {
        return outputText11;
    }

    public void setColumn10(CoreColumn column10) {
        this.column10 = column10;
    }

    public CoreColumn getColumn10() {
        return column10;
    }

    public void setOutputText12(CoreOutputText outputText12) {
        this.outputText12 = outputText12;
    }

    public CoreOutputText getOutputText12() {
        return outputText12;
    }
    public void seccionChange(ValueChangeEvent evt){
        UIComponent c = evt.getComponent();  
        c.processUpdates(FacesContext.getCurrentInstance());
        executeWith("ExecuteWithParamsSeccion");
    }
    
    public void nivelChange(ValueChangeEvent evt){
        UIComponent c = evt.getComponent();  
        c.processUpdates(FacesContext.getCurrentInstance());
        executeWith("ExecuteWithParamsNivel");
        executeWith("ExecuteWithParamsSeccion");
    }
    
    public void anioChange(ValueChangeEvent evt){
        UIComponent c = evt.getComponent();  
        c.processUpdates(FacesContext.getCurrentInstance());
        executeWith("ExecuteWithParamsTemporada");
        executeWith("ExecuteWithParamsSeccion");
    }
    public void executeWith(String instruccion){
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = bindings.getOperationBinding(instruccion);
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
                   return;
        }
    }

    public void setBindings(BindingContainer bindings) {
        this.bindings = bindings;
    }

    public BindingContainer getBindings() {
        return bindings;
    }

    public void setOutputText3(CoreCommandLink outputText3) {
        this.outputText3 = outputText3;
    }

    public CoreCommandLink getOutputText3() {
        return outputText3;
    }

    public String printActa_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = bindings.getOperationBinding("setCurrentRowWithKey");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
           return null;
       }
        AppModuleImpl service = getService();
        idiomaNivelSeccionViewImpl ids = service.getidiomaNivelSeccionView3();
        Row seccion = ids.getCurrentRow();
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("/viewcontroller/printcoordinacion?reporte=acta&panio="+seccion.getAttribute("Anio")+"&ptemporada="+seccion.getAttribute("IdTipoTemporada")+"&pseccion="+seccion.getAttribute("Seccion")+"&ptipocurso="+seccion.getAttribute("TipoCurso")+"&pnivel="+seccion.getAttribute("IdNivel")+"&pidioma="+seccion.getAttribute("IdIdioma"));
        } catch (IOException e) {
            // TODO
        }
       
        return null;
    }
    
    private AppModuleImpl getService(){
        FacesContext ctx = FacesContext.getCurrentInstance();
        
        //Creando el binding container 
        ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
        BindingContext bc = (BindingContext)vb.getValue(ctx);
        
        DCDataControl dc  = bc.findDataControl("AppModuleDataControl");
        ApplicationModule am = (ApplicationModule)dc.getDataProvider();
        return (AppModuleImpl)am;
    }
}
